<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>排序考察</title>
</head>
<body>
	<script type="text/javascript">
		var bubble = function (arr) {
			var len = arr.length;
			for(var i = 0; i < len; i++){
				for(var j = 1; j < len - i; j++) {
					if (arr[j-1] > arr[j]) {
						var temp = arr[j-1];
						arr[j-1] = arr[j];
						arr[j] = temp;
					}
				}				
			}
			return arr;
		}

		var A = [2,4,3,1,0];
		// console.log(bubble(A));

		var quickSort = function (arr) {
			var len = arr.length;
			if (len <= 1) {
				return arr;
			}

			var p = arr[0];
			var left = [];
			var right = [];
			for(var i = 1; i < len; i++){
				if (arr[i] < p) {
					left.push(arr[i]);
				} else {
					right.push(arr[i]);
				}
			}
			return quickSort(left).concat(p,quickSort(right));
		} 
		// console.log(quickSort(A));
		var selectSort = function (arr) {
			var len = arr.length;
			var min;
			var resort = [];
			for(var i = 0; i < len; i++){
				min = Math.min.apply(null,arr);
				resort.push(min);
				arr.splice(arr.indexOf(min),1);
			}
			return resort;
		}
		console.log(selectSort(A));
		
	</script>

</body>
</html>